package dancrawler.common;

import java.io.File;

/**
 *
 */
public class Misc {

    public static short bytesToShort(byte[] bytes) {
        short x = (short) ((bytes[0] & 0xFF) << 8);
        x = (short) ((x | (bytes[1] & 0xFF)));
        return x;
    }

    public static byte[] shortToBytes(short s) {
        byte[] ret = new byte[2];
        ret[1] = (byte) (s & 0xff);
        ret[0] = (byte) ((s >> 8) & 0xff);
        return ret;
    }

    public static String getAppdataPath(String name) {
        String path;
        path = System.getenv("APPDATA");
        if (path != null) {
            File f = new File(path + "/" + name);
            f.mkdir();
            return f.getAbsolutePath();
        }

        path = System.getenv("HOME");
        if (path != null) {
            File f = new File(path + "./" + name);
            f.mkdir();
            return f.getAbsolutePath();
        }
        return null;
    }

    public static byte[] stringToBytes(String s) {
        byte[] b = s.getBytes();
        return b;
    }
}
